package com.bw.zonghe0719

import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.bw.base.mvvm.BaseViewActivity
import com.bw.zonghe0719.adapter.FragmentAdapter
import com.bw.zonghe0719.adapter.MyTab
import com.bw.zonghe0719.databinding.ActivityWelComeBinding
import com.bw.zonghe0719.fragment.welcome.BlankFragment1
import com.bw.zonghe0719.fragment.welcome.BlankFragment2
import com.bw.zonghe0719.fragment.welcome.BlankFragment3
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
@Route(path = "/app/WelComeActivity")
class WelComeActivity :BaseViewActivity<ActivityWelComeBinding>(){
    private lateinit var fragmentAdapter:FragmentAdapter
    var list= mutableListOf<Fragment>()
    var listTab= ArrayList<CustomTabEntity>()
    override fun initView() {
        list.add(BlankFragment1())
        list.add(BlankFragment2())
        list.add(BlankFragment3())
        fragmentAdapter=FragmentAdapter(this,list)
        binding.vp2.adapter=fragmentAdapter
        listTab.add(MyTab("",R.drawable.baseline_horizontal_rule_24,R.drawable.baseline_circle_24))
        listTab.add(MyTab("",R.drawable.baseline_horizontal_rule_24,R.drawable.baseline_circle_24))
        listTab.add(MyTab("",R.drawable.baseline_horizontal_rule_24,R.drawable.baseline_circle_24))
        binding.tab.setTabData(listTab)
        binding.tab.setOnTabSelectListener(object :OnTabSelectListener{
            override fun onTabSelect(position: Int) {
                binding.vp2.currentItem=position
            }

            override fun onTabReselect(position: Int) {

            }

        })
        binding.vp2.registerOnPageChangeCallback(object :OnPageChangeCallback(){
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                binding.tab.currentTab=position
            }
        })
        //获取上次离开时间  小于1分钟进入不展示欢迎页   大于1分钟进入展示欢迎页
        val long=SPUtils.getInstance().getLong("time")
        if(System.currentTimeMillis()-long<60*1000){
            ARouter.getInstance().build("/app/MainActivity").navigation()
        }



    }

    override fun initData() {

    }

    override fun getLayoutId(): Int {
       return R.layout.activity_wel_come
    }
}